﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;


namespace pufflesweb
{
    public partial class Agoodsadd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PModel.Goods goods = new PModel.Goods();
            goods.Gname = this.gname.Text.Trim();
            goods.Gprice = int.Parse(this.gprice.Text.Trim());
            goods.Gnumber = int.Parse(this.gnumber.Text.Trim());
            goods.Gtitle = this.gtitle.Text.Trim();
            goods.Gtext = this.gtext.Text.Trim();
            goods.Gaddress = this.gaddress.Text.Trim();
            goods.Gtype = int.Parse(this.DropDownList1.Text.Trim());
            goods.Gstate = int.Parse(this.DropDownList2.Text.Trim());

            if (img.HasFile)
            {
                string filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString()+ Path.GetExtension(img.FileName);
                string filePath = "~/goodsimg/" + filename;
                img.SaveAs(MapPath(filePath));
                goods.Gimage = filename;
            }

            if (PBLL.Goods.add(goods))
            {
                PF.JsHelper.AlertAndParentUrl("发布成功", "Agoods.aspx");
            }
            else
            {
                PF.JsHelper.AlertAndParentUrl("发布失败,请重新输入", "Agoodsadd.aspx");
            }
        }
    }
}